package stalker.room.roomusers;

import junit.framework.Assert;

import org.junit.Test;

import stalker.room.RoomAction;
import stalker.user.User;

public class RoomUsersTest {

  @Test
  public void testRoomUsers() {
    User irvan = User.createUser("Irvan");
    User gogo = User.createUser("Gogo");
    
    RoomUsers users = new PublicRoomUsers();
    for (RoomAction action : RoomAction.values()) {
      Assert.assertFalse("RoomUsers: testIsAuthorized fails", 
          users.isAuthorized(irvan, action));
      Assert.assertFalse("RoomUsers: testIsAuthorized fails",
          users.isAuthorized(gogo, action));
    }
    users.addUser(irvan);
    for (RoomAction action : RoomAction.values()) {
      Assert.assertTrue("RoomUsers: testIsAuthorized fails", 
          users.isAuthorized(irvan, action));
      Assert.assertFalse("RoomUsers: testIsAuthorized fails",
          users.isAuthorized(gogo, action));
    }
    users.addUser(irvan);
    for (RoomAction action : RoomAction.values()) {
      Assert.assertTrue("RoomUsers: testIsAuthorized fails", 
          users.isAuthorized(irvan, action));
      Assert.assertFalse("RoomUsers: testIsAuthorized fails",
          users.isAuthorized(gogo, action));
    }
    users.addUser(gogo);
    for (RoomAction action : RoomAction.values()) {
      Assert.assertTrue("RoomUsers: testIsAuthorized fails", 
          users.isAuthorized(irvan, action));
      Assert.assertTrue("RoomUsers: testIsAuthorized fails",
          users.isAuthorized(gogo, action));
    }
  }

  @Test(expected=AssertionError.class)
  public void testNullUserAuthorize() {
    RoomUsers users = new PublicRoomUsers();
    System.out.println(users.isAuthorized(null, RoomAction.kRead));
  }

  @Test(expected=AssertionError.class)
  public void testAddNullUser() {
    RoomUsers users = new PublicRoomUsers();
    users.addUser(null);
  }
  
  @Test(expected=AssertionError.class)
  public void testNullActionAuthorize() {
    RoomUsers users = new PublicRoomUsers();
    User irvan = User.createUser("Tampan");
    System.out.println(users.isAuthorized(irvan, null));
  }

}
